﻿using SAO.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace SAO.OracleHelper.ValiDateModel
{
    [AttributeUsage(AttributeTargets.Property)]
    public class StringLengthAttribute : ValidateAttribute
    {
        private int _MaxLength { get; set; }
        private int _MinLength { get; set; }
        public StringLengthAttribute(int max, int min)
        {
            _MaxLength = max;
            _MinLength = min;
        }
        public override ResultMsg Validate(object value)
        {
            ResultMsg resultMsg = new ResultMsg();
            if (value == null || value.ToString().Length < _MinLength || value.ToString().Length > _MaxLength)
            {
                resultMsg.Msg = $"{_PropName}长度不符合规范";
            }
            return resultMsg;
        }
    }
}
